package com.android.phoenix.activity.changeInfo;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.Toast;
import android.widget.TextView;

import com.android.phoenix.Constant;
import com.android.phoenix.MainApplication;
import com.android.phoenix.R;
import com.android.phoenix.activity.BaseActivity;

public class ChangeSexActivity extends BaseActivity{
	private TextView tvCenter;
	private ImageView imgBack; 
	private Button btnConfirm;
	private RadioButton rbUserInfoMale = null;
	private RadioButton rbUserInfoFemale = null;
	private TextView title_txt_right_up;
	
	private SharedPreferences mShare;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.acti_user_change_sex);
		mShare = MainApplication.mSharedPreferences;
		
		tvCenter = (TextView) findViewById(R.id.title_txt_center);
		tvCenter.setText(getResources().getString(R.string.txt_myinfo_change_sex));
		
		title_txt_right_up = (TextView) findViewById(R.id.title_txt_right_up);
		title_txt_right_up.setVisibility(View.GONE);
		
		btnConfirm = (Button) findViewById(R.id.btnConfirm);
		
		rbUserInfoMale = (RadioButton) findViewById(R.id.rbUserInfoMale);
		rbUserInfoFemale = (RadioButton) findViewById(R.id.rbUserInfoFemale);
		
		if(Constant.FEMALE == mShare.getInt(Constant.USERSEX, 0)){
			rbUserInfoFemale.setChecked(true);
		} else {
			rbUserInfoMale.setChecked(true);
		}
		
		imgBack = (ImageView) findViewById(R.id.title_Imgbtn_left_up);
		imgBack.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		
		btnConfirm.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if (rbUserInfoMale.isChecked()) {
					saveUserSex(Constant.MALE);
				} else if (rbUserInfoFemale.isChecked()) {
					saveUserSex(Constant.FEMALE);
				} else {
					Toast.makeText(ChangeSexActivity.this, "请选择性别", Toast.LENGTH_SHORT)
							.show();
					return;
				}
				finish();
			}
		});
		
	}
	
	private void saveUserSex(int sex) {
		mShare.edit().putInt(Constant.USERSEX, sex)
				.commit();
	}
}
